
Apply Models
Generate spatial predictions across a landscape
Hong Jhun Sim
2022-09-05
Source:vignettes/apply-models.Rmd
apply-models.RmdThis article outlines the steps to predict the number of species (species richness) for a particular animal group, across a target landscape. The pixel-based predictions are then visualised in the form of a spatial heatmap. Begin by loading the required packages to run the analysis:
library("biodivercity")
library("dplyr") # to process/wrangle data
library("tmap") # for visualisationThe biodivercity package contains predictive models (lme4::glmer()) and data pre-processing workflow ‘recipes’ (recipes::recipe()) that were built for each of four animal groups surveyed in Singapore. Refer to vignette("build-models") for more details on these models, which were built using the example data in this package. In this article, the model/recipe used to predict the number of bird species will be used as an example. Alternatively, the user may provide their own model/recipe for the analysis.
Load the model/recipe objects built exclusively from manually-generated landscape data:
filepath <- system.file("extdata", "models-manually-mapped.Rdata", package = "biodivercity")
load(filepath)Landscape data within the target area of interest will be used to make spatial predictions. They will be summarised according to the predictor variables present in the models. For example, predictor variables in the bird model can be extracted as follows. Note that the prefix r<value>m denotes the buffer radius that the particular landscape data was summarised within, and _man_ denotes that the variables were generated from manually-generated data.
predictors_birds <- models_birds %>% # a list object
lapply(function(x) names(x@frame)) %>% # extract variable names in model
unlist() %>%
unique() %>%
stringr::str_subset("(?<=^r)\\d+.*") # predictor variables start with the "r<value>m_"
predictors_birds## [1] "r126m_man_natveg_pland" "r50m_man_buildingFA_ratio"
## [3] "r50m_man_laneDensity" "r50m_man_tree_sprich"
## [5] "r50m_man_water_pland" "r50m_man_shrub_pland"
## [7] "r50m_man_turf_pland" "r50m_man_shrub_sprich"
The following list describes the manually-generated landscape components used to build models provided in this package, their respective vector format, as well as all the possible predictor variables that may be summarised:
- Natural vegetation (polygons)
- Percentage of landscape area (
natveg_pland)
- Percentage of landscape area (
- Trees (points) with species name (per point)
- Species richness (
tree_sprich)
- Species richness (
- Shrubs (polygons) with species name (per polygon)
- Percentage of landscape area (
shrub_pland) - Species richness (
shrub_sprich)
- Percentage of landscape area (
- Turf (polygons)
- Percentage of landscape area (
turf_pland)
- Percentage of landscape area (
- Water (polygons)
- Percentage of landscape area (
water_pland)
- Percentage of landscape area (
- Buildings (polygons) each with the number of levels
- Floor area ratio (
buildingFA_ratio)
- Average number of levels (
buildingAvgLvl)
- Floor area ratio (
- Roads (lines) each with the number of lanes
- Lane density (
laneDensity)
- Lane density (
To demonstrate how spatial predictions may be generated, load the example landscape data from within the Punggol (PG) area in Singapore (Chong et al., 2014, 2019), visualised in the interactive map below. Note that there are no water bodies mapped in the target area.
filepath <- system.file("extdata", "pg_layers.Rdata", package = "biodivercity")
load(filepath)